# -*- coding: UTF-8 -*-
# @Time : 2021/12/23 0023 13:39
# @Author : lyw
# @Remark : 普通空调控制
from mxsoftpy import View

from index import _
from server.common.IOTManager.AirConditioner.modbus_ac import (ACSelectServer, ACUpdateServer, ACSetServer,
                                                               ACRetrieveServer, ACHintServer)
from utils.public.params_method import check_params


class ACSelectView(View):

    def post(self):
        param = self.request.POST
        if param.get("ac_run"):
            param["ac_run"] = "关" if param["ac_run"] == "0" else "开"
        return _("查询成功"), ACSelectServer().select(**param)


class ACUpdateView(View):

    def post(self):
        check_params(self.request.POST, ["ac_code", "ac_option", "option"])
        return _("操作成功"), ACUpdateServer().update(**self.request.POST)


class ACSetView(View):

    def post(self):
        check_params(self.request.POST, ["ac_code", "upper_limit", "lower_limit", "hysteresis", "running_list"])
        return _("更新成功"), ACSetServer().update(**self.request.POST)


class ACRetrieveView(View):

    def post(self):
        check_params(self.request.POST, ["ac_code"])
        return _("操作成功"), ACRetrieveServer().retrieve(**self.request.POST)


class ACHintView(View):

    def post(self):
        check_params(self.request.POST, ["ac_code"])
        return _("查询成功"), ACHintServer().retrieve(**self.request.POST)
